package com.feihao.zhou.review;

public class Cooker implements Runnable {
    public BaoZi baoZi;

    public Cooker(BaoZi baoZi) {
        this.baoZi = baoZi;
    }

    @Override
    public void run() {
        while (true) {
            synchronized (baoZi) {
                if (baoZi.getCount() == 0) {
                    break;
                }
                if (!baoZi.isFlag()) {//没有包子！则做
                    System.out.println("厨师正在做包子");
                    baoZi.setFlag(true);
                    baoZi.notify();
                } else {
                    try {
                        baoZi.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }
}
